import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/JunM/login/login.vue'),
  },
  {
    path:'/setmeal',
    name:'setmeal',
    component:()=>import('../views/JunM/meal/setmeal.vue'),
    // children:[
    //   { path:'setmealdetail',
    //     name:'setmealdetail',
    //     component:()=>import('../views/JunM/meal/setmealdetail.vue')
    //   }
    // ]
  },
  { path:'/setmealdetail',
    name:'setmealdetail',
    component:()=>import('../views/JunM/meal/setmealdetail.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
   {
     path:'/assess',
     name:'assess',
     component: () => import('../views/xsf/Assess'),
     children:[
       {
         path:"/riskAssessment",
         name:"riskAssessment",
         component:() =>import('../components/assess/riskAssessment.vue'),
         meta: {
          needLogin: true //需要加校检判断的路由
        },
       },
       {
         path:"/constitutionIdentification",
         name:"constitutionIdentification",
         component:() =>import('../components/assess/constitutionIdentification.vue'),
         meta: {
          needLogin: true //需要加校检判断的路由
        }
       },
       {
         path:"/psychologicalQuestion",
         name:"psychologicalQuestion",
         component:() =>import('../components/assess/PsychologicalQuestion.vue'),
         meta: {
          needLogin: true //需要加校检判断的路由
        }
       }
     ]
   },

  {
    path:'/order',
    name:'order',
    component:()=>import('../views/JunM/order/order.vue')
  },
  {
    path:'/orderapply',
    name:'orderapply',
    component:()=>import('../views/JunM/order/orderapply.vue'),
    /*meta: {
      needLogin: true //需要加校检判断的路由
    },*/
  },

  {
    path:'/interpose',
    name:'interpose',
    component: () => import('../views/xsf/interpose'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
  {
    path:'/information',
    name:'information',
    component: () => import('../views/xsf/HealthyInformation.vue'),
    children:[
      {
        path:'/informationmain',
        name:'informationmain',
        component: () => import('../components/healthyInformation/InformationMain')
      },
      {
        path:"/mainQuestion",
        component:()=> import("../components/healthyInformation/MainQuestion.vue")
      },
      {
        path:"/InformationDoctor",
        component:()=>import("../components/healthyInformation/InformationDoctor.vue")
      },
      {
        path:"/InformationOnline",
        component:()=>import("../components/healthyInformation/InformationOnline.vue"),
        meta: {
          needLogin: true //需要加校检判断的路由
        },
      },
      {
        path:"/doctorInformation",
        name:"doctorInformation",
        component:()=>import("../components/healthyInformation/DoctorInformation.vue")
      }
    ]
  },
  {
    path: '/healthHome',
    name: 'healthHome',
    component: () => import('../views/JunM/health/healthHome.vue')
  },
  {
    path: '/healthBasic',
    name: 'healthBasic',
    component: () => import('../views/JunM/health/healthBasic.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
  {
    path: '/checkReprot',
    name: 'checkReprot',
    component: () => import('../views/JunM/report/checkReprot.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
  {
    path: '/vaccinType',
    name: 'vaccinType',
    component: () => import('../views/JunM/vaccin/vaccinType.vue'),
  },
  {
    path: '/consult',
    name: 'consult',
    component: () => import('../views/JunM/vaccin/consult.vue'),
  },
  {
    path: '/vaccinOrder',
    name: 'vaccinOrder',
    component: () => import('../views/JunM/vaccin/vaccinOrder.vue'),
  },
  {
    path: '/vaccinCheck',
    name: 'vaccinCheck',
    component: () => import('../views/JunM/vaccin/vaccinCheck.vue'),
  },
  {
    path: '/vaccinApply',
    name: 'vaccinApply',
    component: () => import('../views/JunM/vaccin/vaccinApply.vue'),
  },
  {
    path: '/caseHistory',
    name: 'caseHistory',
    component: () => import('../views/JunM/case/caseHistory.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
  {
    path:'/vaccinRecord',
    name:'vaccinRecord',
    component:()=>import('../views/JunM/vaccin/vaccinRecord.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
  {
    path:'/ko',
    name:'ko',
    component:()=>import('../views/JunM/koNULL/koNULL.vue'),
    meta: {
      needLogin: true //需要加校检判断的路由
    },
  },
]



const router = new VueRouter({
  routes
})

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
router.beforeEach(async (to, from, next) => {
  if (to.meta.needLogin) {
    //页面是否登录
    if (localStorage.getItem("user")) {
      //本地存储中是否有token(uid)数据
      next(); //表示已经登录
    } else {
      //next可以传递一个路由对象作为参数 表示需要跳转到的页面
      next({
        name: "login"
      });
    }
  } else {
    //表示不需要登录
    next(); //继续往后走
  }
})